home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17440 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  75 lines

  1. Newsgroups: comp.lang.c++
  2. Path: twisto.eng.hou.compaq.com!news
  3. From: Cindy McGee <cindym@bangate.compaq.com>
  4. Subject: Problem:  Incorrect ifstream handling?
  5. Message-ID: <3172E386.28C@bangate.compaq.com>
  6. Sender: news@twisto.eng.hou.compaq.com (System Administrator)
  7. Mime-Version: 1.0
  8. X-Mailer: Mozilla 2.0 (Win95; I)
  9. Content-Type: text/plain; charset=us-ascii
  10. Organization: Compaq Computer Corporation
  11. Date: Tue, 16 Apr 1996 00:02:14 GMT
  12. X-Nntp-Posting-Host: 172.18.220.53
  13. Content-Transfer-Encoding: 7bit
  14.  
  15. My reference material doesn't seem to clear on this subject.
  16.  
  17. I'm using an input file stream to read data from a text file inside a 
  18. MSVC++ 4.0 console application.  The code actually compiles and runs 
  19. normally, but with Bounds Checker for W95, I get several errors. 
  20.  
  21. Specifically, BC reports an "Invalid argument operator delete, HANDLE 
  22. 0x01101350, Bad handle" in the streambuf destructor, a "Dynamic memory 
  23. overrun 548 byte block allocated in malloc.c at line 160 HANDLE 
  24. 0x01101330 Allocating thread ID... current thread ID...", another 
  25. "invalid argument..." in the filebuf's scalar deleting destructor, and 
  26. so on.  Other, bigger objects have dynamic memory overruns that may be 
  27. affected by this function.
  28.  
  29. Without BC, I can run the app, but get strange behavior later with the 
  30. bigger objects.  For instance, inside 
  31. TheApp->pOb->FooFoo(), iTheApp->pOb->m_iXxx is initialized, but 
  32. this->m_iXxx is uninitialized and refuses to take an assignment.
  33.  
  34. I seem to have either a memory allocation/de-allocation problem, faulty 
  35. standard library classes, or a ifstream class handled incorrectly.
  36.  
  37. Any ideas would be appreciated; I've included a code snippet below.
  38.  
  39.  
  40. Thanks!
  41.  
  42. Cindy McGee
  43. --------------
  44. <cindym@bangate.compaq.com>
  45.  
  46. ==============================================
  47. Given szFileName as "text.emu", my function performs the following:
  48.  
  49. ifstream file(szFileName);
  50.  
  51. if (!file)
  52.    // ... error handling
  53. else
  54. {
  55.    int iMax = 0;
  56.    char sz[255];
  57.  
  58.    file >> iMax;
  59.    file >> sz;
  60.  
  61.    for (int i = 0; i < iMax; i++)
  62.    {
  63.       if (0 == strcmp(sz,"<field1>"))
  64.       {
  65.     file.eatwhite()
  66.     file.getline(sz,255);
  67.     pObject->Setxxx(sz);
  68.     file >> sz;
  69.       }
  70.  
  71.       // ... many repeats of the above for different fields
  72.    }
  73.  
  74. // function returns
  75.